package com.atguigu.study.bootredis.juc;

import java.util.concurrent.*;

/**
 * @author jiangta
 * @version 1.0
 * @date 2020/12/15 7:42 下午
 */
public class Task implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        // 模拟计算需要一秒
        Thread.sleep(1000);
        return 2;
    }

    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newCachedThreadPool();
        //Task task = new Task();
        FutureTask<Integer> futureTask = new FutureTask<>(new Task());
        executorService.submit(futureTask);
        Integer integer = futureTask.get();
        System.out.println(integer);
    }
}
